
import HouseAPI from '../api/house.js';

export const House={
   state:{
      houselist:[],
      house_total_count:0,
      editHouseStatus:-1,     //插入状态 0失败  1成功  -1不改变
      houseinfo:[],
      delHouseStatus:-1,       //删除状态
      allhouselist:[]          //所有房屋列表，小区
   },
   mutations:{
      setHouseList(state,list){
          state.houselist=list;
      },
      setHouseTotalCount(state,total_count){
          state.house_total_count=total_count;
      },
      setEditHouseStatus(state,status){
          state.editHouseStatus=status;
      },
      setHouseInfo(state,info){
          state.houseinfo=info;
      },
      setDelHouseStatus(state,status){
          state.delHouseStatus=status;
      },
      setAllHouseList(state,list){
          state.allhouselist=list;
      }
   },
   actions:{
      loadHouseList(context,data){
          HouseAPI.getHouseList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setHouseList',response.data.list);
                  context.commit('setHouseTotalCount',response.data.total_count);
              }
          })
      },
      //插入House
      editHouse(context,data){
          HouseAPI.editHouse(data).then(function(response){
              context.commit('setEditHouseStatus',response.data.code);
          })
      },
      //获取详情
      loadHouseInfo(context,data){
          HouseAPI.getHouseInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setHouseInfo',response.data.info);
              }
          })
      },
      //删除
      delHouse(context,data){
          HouseAPI.delHouse(data).then(function(response){
                context.commit('setDelHouseStatus',response.data.code);
          })
      },
      loadAllHouseList(context,data){
          HouseAPI.getAllHouseList(data).then(function(response){
                context.commit('setAllHouseList',response.data.list);
          })
      }
   },
   getters:{
      getHouseList:state =>{
         return state.houselist
      },
      getHouseTotalCount: state =>{
         return state.house_total_count
      },
      getEditHouseStatus:state=>{
          return state.editHouseStatus;
      },
      getHouseInfo:state => {
          return state.houseinfo;
      },
      getDelHouseStatus:state => {
          return state.delHouseStatus;
      },
      getHouseType:state => {
          return state.housetype;
      },
      getAllHouseList:state=>{
          return state.allhouselist;
      }
   }
}
